package com.lucky.common.config;

import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

@Configuration
@EnableJdbcHttpSession(tableName = "mcp_spring_session")
public class SpringSessionConfig {

    @Value("${app.domain}")
    public String domain;

    /**
     * 设置热session cookie name 以及子域共享
     *
     * @return
     */
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();

        serializer.setDomainName(domain);
        serializer.setCookieName("app_jsessionid");//lucky_jssid
        serializer.setCookiePath("/");
		serializer.setCookieMaxAge(3600);
//		serializer.setSameSite("Lax");  // 设置SameSite属性
        serializer.setUseHttpOnlyCookie(true);
        serializer.setUseBase64Encoding(true);
        serializer.setUseSecureCookie(true);
        //serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$");
        return serializer;
    }


}
